import 'package:flutter/material.dart';
import 'package:hello_flutter/base/index.dart';

class GridViewWidget extends BasePage {
  const GridViewWidget({super.key});

  @override
  String getPageTitle() => 'GridView';

  @override
  Widget buildBody(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          buildFixedCrossAxisCountGridView(),
          const Divider(),
          buildMaxCrossAxisExtentGridView(),
          const Divider(),
          buildCountGridView(),
          const Divider(),
          buildExtentGridView(),
          const Divider(),
        ],
      ),
    );
  }

  List<Widget> generateIcons() {
    return [
      const Icon(Icons.ac_unit),
      const Icon(Icons.airport_shuttle),
      const Icon(Icons.all_inclusive),
      const Icon(Icons.beach_access),
      const Icon(Icons.cake),
      const Icon(Icons.free_breakfast),
    ];
  }

  Widget buildFixedCrossAxisCountGridView() {
    return Column(
      children: [
        const Text('FixedCrossAxisCountGridView'),
        Container(
          color: Colors.amber.shade100,
          height: 200,
          child: GridView(
            // shrinkWrap: true,
            // physics: const NeverScrollableScrollPhysics(),
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              childAspectRatio: 1,
            ),
            children: generateIcons(),
          ),
        ),
      ],
    );
  }

  Widget buildMaxCrossAxisExtentGridView() {
    return Column(
      children: [
        const Text('MaxCrossAxisExtentGridView'),
        Container(
          color: Colors.amber.shade100,
          height: 200,
          child: GridView(
            gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
              maxCrossAxisExtent: 100,
              childAspectRatio: 1,
            ),
            children: generateIcons(),
          ),
        ),
      ],
    );
  }

  Widget buildCountGridView() {
    return Column(
        children: [
          const Text('CountGridView'),
          Container(
            color: Colors.amber.shade100,
            height: 200,
            child: GridView.count(
              crossAxisCount: 3,
              childAspectRatio: 1,
              children: generateIcons(),
            ),
          ),
        ],
    );
  }

  Widget buildExtentGridView() {
    return Column(
      children: [
        const Text('ExtentGridView'),
        Container(
          color: Colors.amber.shade100,
          height: 200,
          child: GridView.extent(
            maxCrossAxisExtent: 110,
            childAspectRatio: 1,
            children: generateIcons(),
          ),
        ),
      ],
    );
  }
}
